package dao

import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import javax.inject.{Inject, Singleton}
import scala.concurrent.ExecutionContext.Implicits.global

/**
 * Created by yz on 2018/7/17
 */
@Singleton
class AssemblyDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  type MyRow=AssemblyRow
  val table=Assembly

  def insertAll(rows: List[MyRow]) = db.run(table ++= rows).map(_ => ())

  def deleteAll = db.run(table.delete).map(_ => ())

  def selectAll= db.run(table.result)

  def select(id: String) = db.run(table.
    filter(_.assembly === id).result.head)

}
